package com.evamay.kotlindemo.ui.rxdemo

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.evamay.kotlindemo.R
import com.evamay.kotlindemo.entity.TypeInfo
import com.evamay.kotlindemo.ui.main.MainAdapter
import kotlinx.android.synthetic.main.activity_rx_main.*
import java.time.Instant

class RxMenuActivity :AppCompatActivity(){

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_rx_main)
        initData()
    }

    private fun initData() {
        var list=ArrayList<TypeInfo>()
        list.add(TypeInfo(1,"Rx基础用法ByJava"))
        list.add(TypeInfo(2,"Rx基本操作ByKotlin"))
        var mAdapter=MainAdapter(baseContext,list)
        rv_rx_main.layoutManager=LinearLayoutManager(this)
        rv_rx_main.adapter=mAdapter
        mAdapter.setClickListener(object :MainAdapter.OnItemClickListener{
            override fun onItemClick(position: Int) {
                if (list[position].type == 1) {
                    var intent=Intent(baseContext,RxDemoByJavaActivity::class.java)
                    intent.putExtra("type",list[position].type)
                    startActivity(intent)
                } else {
                    var intent=Intent(baseContext,RxDemoActivity::class.java)
                    intent.putExtra("type",list[position].type)
                    startActivity(intent)
                }

            }

        })
    }

}